package cn.szabadsag.product.service.impl;


import cn.szabadsag.base.service.impl.BaseServiceImpl;
import cn.szabadsag.product.domain.Product;
import cn.szabadsag.product.domain.ProductDetail;
import cn.szabadsag.product.mapper.ProductDetailMapper;
import cn.szabadsag.product.mapper.ProductMapper;
import cn.szabadsag.product.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductServiceImpl extends BaseServiceImpl<Product> implements IProductService {

    @Autowired
    private ProductMapper productMapper;

    @Autowired
    private ProductDetailMapper productDetailMapper;

    /**
     * 宠物领养下架
     * @param list
     */
    @Override
    public void offsale(List<Long> list) {
        productMapper.offsale(list);
    }

    /**
     * 宠物领养上架
     * @param list
     */
    @Override
    public void onsale(List<Long> list) {
        productMapper.onsale(list);
    }

    @Override
    public Product loadByIdDetail(Long id) {
        Product product = productMapper.loadByIdDetail(id);
        System.out.println("数据库查询的product:" + product);
        return product;
    }


    /**
     * 新增宠物领养
     */
    @Override
    public void save(Product product) {

        ProductDetail productDetail = product.getDetail();
        //获取当前的登录用户【Employee】
        //pet.setShop_id(27L);
        //super.save(pet);
        //设置关联属性
        //  设置pet_id
        //pet.getDetail().setPet_id(pet.getId());
        //petDetailMapper.save(pet.getDetail());
        productMapper.save(product);

        productDetail.setProduct_id(product.getId());

        productDetailMapper.save(productDetail);
    }


    /**
     * 新增宠物领养
     */
    @Override
    public void update(Product product) {
        ProductDetail productDetail = product.getDetail();
        productMapper.update(product);
        productDetail.setProduct_id(product.getId());
        productDetailMapper.update(productDetail);
    }
}
